package com.example.demo.controller;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
// @ResponseBody
//@RequestMapping
public class ReturnController {

    /**
     * 返回静态页面
     * @return
     */
    @RequestMapping("/index")
    public Object getIndex() {
        return "/index.html";
    }

    /**
     * 请求转发
     * @return
     */
    @RequestMapping("/forward")
    public String forward() {
        return "forward:/index.html";
    }

    /**
     * 请求重定向
     * @return
     */
    @RequestMapping("/redirect")
    public String redirect() {
        return "redirect:/index.html";
    }

    /**
     * 用 HttpservletResponse 对象来进行重定向
     * @return
     */
    @RequestMapping("/redirect2")
    public void redirect2(HttpServletResponse response) throws IOException {
        response.sendRedirect("https://www.baidu.com" );
    }

}
